In [1]:
import numpy as np
from matplotlib import pyplot as plt
from __future__ import division
from itertools import product
from spacetime.CA_Simulators.CAs import *
from spacetime.Local_Measures.Transducers import *
%matplotlib inline

In [2]:
print rule_number_conversion(54, 2, 1)


00110110

In [3]:
start = np.zeros(20, dtype = int)
example = ECA(54, start)
print 'full lookup table'
example.lookup_table(True)
print 'lookup table value for neighborhood (0,0,1)'
print example.lookup_table()[(0,0,1)]


full lookup table
(1, 1, 1) 0
(1, 1, 0) 0
(1, 0, 1) 1
(1, 0, 0) 1
(0, 1, 1) 0
(0, 1, 0) 1
(0, 0, 1) 1
(0, 0, 0) 0
lookup table value for neighborhood (0,0,1)
1

In [4]:
print rule_number_conversion(18, 2, 1)


00010010

In [5]:
start = np.zeros(20, dtype = int)
example = ECA(18, start)
print 'full lookup table'
example.lookup_table(True)
print 'lookup table value for neighborhood (0,0,1)'
print example.lookup_table()[(0,0,1)]


full lookup table
(1, 1, 1) 0
(1, 1, 0) 0
(1, 0, 1) 0
(1, 0, 0) 1
(0, 1, 1) 0
(0, 1, 0) 0
(0, 0, 1) 1
(0, 0, 0) 0
lookup table value for neighborhood (0,0,1)
1

Test external lookup table (multi-dimensional np array) code for rule 18


In [6]:
A = 2
r = 1
table = lookup_table(18, 2, 1)
R = 2*r + 1
scan = tuple(np.arange(0,A)[::-1])
for a in product(scan, repeat = R):
    print a, table[a]


(1, 1, 1) 0
(1, 1, 0) 0
(1, 0, 1) 0
(1, 0, 0) 1
(0, 1, 1) 0
(0, 1, 0) 0
(0, 0, 1) 1
(0, 0, 0) 0

In [7]:
x = [0,1,1,0]
print neighborhood(x, 1)
for item in neighborhood(x, 1):
    print item


[array([0, 0, 1, 1]), array([0, 1, 1, 0]), array([1, 1, 0, 0])]
[0 0 1 1]
[0 1 1 0]
[1 1 0 0]

In [8]:
print max_rule(2,1)


255

In [9]:
print example.current_state()
example.evolve(1)
print example.current_state()
example.reset([0,]*5 + [1] + [0,]*5)
print example.current_state()
example.evolve(1)
print example.current_state()


[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 1 0 0 0 0 0]
[0 0 0 0 1 0 1 0 0 0 0]

In [10]:
print np.random.choice([0,1], 10 )


[1 1 1 0 0 0 1 0 0 0]

In [11]:
start = n_ones(20, 1)
test = ECA(18, start)
test.evolve(10)
print test.get_spacetime()
test.rewind(5)
print 'break'
print test.get_spacetime()


[[0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0]
 [0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]
 [0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0]
 [1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0]
 [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1]
 [1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]]
break
[[0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0]
 [0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]
 [0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0]]

In [12]:
domain_state = domain_18(20)
print domain_state
t = transducer(*transducer_18())
print t.scan(domain_state)


[1 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

In [13]:
dim = 400
start = random_state(dim, 2)
test = CA(18, 2, 1, start)
test.evolve(dim)

In [14]:
diagram(test.get_spacetime(), edgecolors='none')


External transduction of CA.get_spacetime()


In [15]:
t = transducer(*transducer_18())
transduced = t.spacetime_scan(test.get_spacetime(), direction ='left')

In [16]:
diagram(transduced, colors = plt.cm.bone, edgecolors = 'none')



In [17]:
masked = t.spacetime_mask(test.get_spacetime(), 2)

In [18]:
diagram(masked, colors = plt.cm.bone, edgecolors = 'none')



In [19]:
filtered = t.spacetime_filter(test.get_spacetime(), fill=True)

In [20]:
diagram(filtered, colors = plt.cm.Blues, edgecolors = 'none')



In [21]:
A = 3
R = 2
print max_rule(A, R)


87189642485960958202911070585860771696964072404731750085525219437990967093723439943475549906831683116791055225665626

In [24]:
start = random_state(500, A)
test = CA(68513215896546121325651496846315418, A, R, start)
test.evolve(500)

In [25]:
diagram(test.get_spacetime(), colors = plt.cm.spring, edgecolors = 'none')



In [ ]: